package main

import (
	"context"
	"database/sql"
	"errors"
	"fmt"
	"github.com/360EntSecGroup-Skylar/excelize"
	"go.manyji.com/lib/log"
	"go.manyji.com/lib/mysql"
	"go.manyji.com/lib/util/convert"
	"reflect"
	"strings"
	"time"
)

// 获取总的充值积分，总的充值赠送积分，总的退款积分
func (a *data_Recharge) GetRechargeTotal(ctx context.Context, accountId uint64) (*GetRechargeTotalType, error) {

	var (
		querySQL = fmt.Sprintf(`
	SELECT
	    account_id,
	    type,
		SUM(recharge_points) as recharge_points_total,
		SUM(bonus_points) as bonus_points_total,
		SUM(refund_points) as refund_points_total
	FROM
	    recharge
	WHERE 
	    account_id = %v AND deleted = 0
	GROUP BY type
`, accountId)
	)

	req, err := db.QueryRaw(ctx, querySQL, GetRechargeTotalType{})
	if err != nil {
		return nil, err
	}

	if req == nil {
		return nil, errors.New(fmt.Sprintf("record not  found"))
	}

	return req[0].(*GetRechargeTotalType), nil
}

func (a *data_Recharge) requestCheck(item map[string]interface{}) error {

	if _, ok := item["type"]; !ok {
		return errors.New("请求参数错误")
	}

	ty := item["type"].(uint64)
	if ty == 1 {

		var rpZero, bpZero bool

		if v, ok := item["recharge_points"]; !ok {
			return errors.New("请填写充值积分")
		} else {
			if v.(uint64) < 0 {
				return errors.New("请输入正确的数字（数据范围(0-9999999)）")
			}
			if v.(uint64) >= 99999990000 {
				return errors.New("数字太大，暂不支持")
			}

			rpZero = v.(uint64) == 0
		}

		if v, ok := item["bonus_points"]; ok {
			if v.(uint64) < 0 {
				return errors.New("请输入正确的数字（数据范围(0-9999999)）")
			}
			if v.(uint64) >= 99999990000 {
				return errors.New("数字太大，暂不支持")
			}

			bpZero = v.(uint64) == 0
		}

		if rpZero && bpZero {
			return errors.New("请填写'充值积分'或者'赠送积分'")
		}
	}

	if ty == 2 {
		if v, ok := item["refund_points"]; ok {
			if v.(uint64) <= 0 {
				return errors.New("请输入正确的数字（数据范围(0-9999999)）")
			}
			if v.(uint64) >= 99999990000 {
				return errors.New("数字太大，暂不支持")
			}
		}
	}

	return nil
}

// 获取总的充值积分，总的充值赠送积分，总的退款积分
func (a *data_Recharge) Create(ctx context.Context, uid uint64, item map[string]interface{}) interface{} {

	if err := a.requestCheck(item); err != nil {
		return err
	}

	var (
		now = time.Now().Unix()
		def = map[string]interface{}{
			"creator":    uid,
			"create_at":  now,
			"updated_at": now,
		}
		totalPointsValue   uint64
		willRefundPoints   uint64
		willRp             uint64
		willBp             uint64
		noCheckAccountSelf bool // 是否不需要检测自己的账户余额是否够本次充值
		ty                 = item["type"].(uint64)
		respCreator        *User // 获取充值人的账户信息
	)

	for k, v := range def {
		item[k] = v
	}

	var (
		logType = "业务日志"
		logName = "充值"
		logMsg  string
	)

	defer func() {
		go func() {
			userInfo := *respCreator
			_ = (&data_User{}).CreateBusinessRecord(ctx, userInfo, logType, logName, logMsg)
			t := time.Now()
			// 只统计充值
			if ty == 1 {
				if err := a.updateRechargeStatistics(time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, time.Local), item["account_id"].(uint64)); err != nil {
					log.Err(fmt.Sprintf("更新充值统计表失败:%+v", err))
				}

				_ = (&data_User{}).updateLastRecharge(ctx, item["account_id"].(uint64), t.Unix())
			}
		}()
	}()

	if _respCreator, err := (&data_User{}).GetUserInfoByUID(ctx, uid, false); err != nil {
		return err
	} else {
		respCreator = _respCreator
	}

	opts := &sql.TxOptions{
		Isolation: sql.LevelReadCommitted,
	}
	err := db.TransactionTx(ctx, func(ctx context.Context, t *mysql.Tx) error {

		//tp, _, _, err := a.getLatestTotalPoints(ctx, item["account_id"].(uint64), true)
		//if err != nil {
		//	log.Err(fmt.Sprintf("get latest total points err:%+v", err))
		//	return err
		//}

		var tp uint64
		_respUser, err := (&data_User{}).GetUserInfoByUID(ctx, item["account_id"].(uint64), true)
		if err != nil {
			log.Err(fmt.Sprintf("get latest total points err:%+v", err))
			return err
		} else {
			tp = _respUser.RechargePoints + _respUser.BonusPoints
		}

		var (
			userBonusPoints uint64
			clearPoints     bool
			extra           = make(map[string]interface{})
		)
		// ty == 1 表示充值
		if ty == 1 {

			if f, ok := item["recharge_points"]; ok {
				totalPointsValue += f.(uint64)
				willRp = f.(uint64)
			}

			if f, ok := item["bonus_points"]; ok {
				totalPointsValue += f.(uint64)
				willBp = f.(uint64)
			}

			/*
				1. 需要判断，充值人的账户余额是否足以支付被充值人的充值积分
				1.1 被充值人的 充值积分和 赠送积分都从充值人处扣除（先扣除赠送积分，再扣除普通积分）
				1.2 被充值人的 赠送积分也是从 充值人处扣除
				1.3 管理员,业务员给代理商充值是没有限额的			--- 此处的逻辑是 管理员,业务员充值是没有限额的,不管给谁充值
			*/

			if (&data_Role{}).IsAdminRoleId(respCreator.RoleId) || (&data_Role{}).IsSalespersonRole(respCreator.RoleId) {
				noCheckAccountSelf = true
			}

			if !noCheckAccountSelf {

				if _respCreator, err := (&data_User{}).GetUserInfoByUID(ctx, uid, true); err != nil {
					return err
				} else {
					respCreator = _respCreator
				}

				//if respCreator.RechargePoints+respCreator.BonusPoints < totalPointsValue {
				//	logType = "异常日志"
				//	logMsg = "账户余额不足以支付本次充值"
				//	return errors.New(logMsg)
				//}

				if respCreator.RechargePoints < willRp || respCreator.BonusPoints < willBp {
					logType = "异常日志"
					logMsg = "账户余额不足以支付本次充值"
					return errors.New(logMsg)
				}

				/*
					1. account_tp 表示充值人的账户总额
					2. account_recharge_points,account_bonus_points 表示给充值人的账户金额(普通积分和赠送积分)
					3. will_recharge_points,will_recharge_points 表示给被充值人的充值金额
				*/

				extra["id"] = respCreator.ID
				extra["will_tp"] = totalPointsValue
				extra["will_recharge_points"] = willRp
				extra["will_bonus_points"] = willBp

				extra["account_tp"] = respCreator.RechargePoints + respCreator.BonusPoints
				extra["account_recharge_points"] = respCreator.RechargePoints
				extra["account_bonus_points"] = respCreator.BonusPoints
			}

		}

		// ty == 2 表示退款
		if ty == 2 {

			// 获取被退款人的账户余额
			_respAccount, err := (&data_User{}).GetUserInfoByUID(ctx, item["account_id"].(uint64), true)
			if err != nil {
				log.Err(fmt.Sprintf("get user info by uid err:%+v", err))
				return err
			}

			if f, ok := item["refund_points"]; ok {
				willRefundPoints = f.(uint64)
			}

			userBonusPoints = _respAccount.BonusPoints
			if _respAccount.RechargePoints < willRefundPoints {
				logType = "异常日志"
				logMsg = "账户余额不足以支持本次退款"
				return errors.New(logMsg)
			}

			// 当账户余额被扣款扣完的时候，赠送余额自动清0
			if _respAccount.RechargePoints == willRefundPoints {
				// 加上 clearPoints = true 防止用户账户赠送余额为0的情况
				clearPoints = true
				userBonusPoints = 0
			}
		}

		// 剩余积分 = 上一次的总积分
		item["residual_points"] = tp
		if ty == 1 {
			totalPointsValue += tp
		}
		if ty == 2 {
			totalPointsValue = tp - willRefundPoints
		}

		item["total_points"] = totalPointsValue

		// 当账户余额被扣款扣完的时候，赠送余额自动清0,充值记录总额也清0
		if ty == 2 && userBonusPoints == 0 && clearPoints {
			item["total_points"] = userBonusPoints
		}

		if ty == 1 && !noCheckAccountSelf {
			if err := (&data_User{}).UpdateUserPoints(ctx, extra); err != nil {
				return err
			}
		}

		if err := a.updateUserRechargeInfo(ctx, item, int(ty), userBonusPoints); err != nil {
			return err
		}

		if err := a.createRetry(ctx, item, 5); err != nil {
			return err
		}
		return nil
	}, opts)

	if err != nil {
		logType = "异常日志"
	}

	return err
}
func (a *data_Recharge) Query(ctx context.Context, uid uint64, pp PaginationParam, queryConditions []string) interface{} {

	queryConditions = append(queryConditions, []string{
		"recharge.deleted = 0",
	}...)
	var (
		condition = fmt.Sprintf(`INNER JOIN user account_user ON account_user.id = recharge.account_id AND account_user.deleted = 0 AND account_user.role_id = %v AND account_user.leader_id = %v
WHERE %v %v`,
			(&data_Role{}).GetChannelAgentRole().ID, uid, strings.Join(queryConditions, " AND "), "ORDER BY recharge.create_at DESC")
		queryCountSQL = fmt.Sprintf(`
	SELECT 
	    COUNT(*)  as count
	FROM recharge
		%v
`, condition)
		querySQL = fmt.Sprintf(`
SELECT
  recharge.id AS id,
  recharge.account_id AS account_id,
  account_user.account AS account_name,
  account_user.leader_id AS leader_id,
  recharge.recharge_points AS recharge_points,
  recharge.bonus_points AS bonus_points,
  recharge.refund_points AS refund_points,
  recharge.total_points AS total_points,
  recharge.residual_points AS residual_points,
  recharge.creator AS creator,
  recharge.create_at AS create_at
FROM recharge
%v %v 
`, condition, fmt.Sprintf(" LIMIT %v OFFSET %v", pp.PageSize, (pp.PageIndex-1)*pp.PageSize))
	)

	log.Info("query count ", queryCountSQL)
	respCount, err := db.QueryRaw(ctx, queryCountSQL, QueryCount{})
	if err != nil {
		return err
	}

	if respCount == nil {
		return nil
	}

	count := respCount[0].(*QueryCount).Count

	respTaskList, err := db.QueryRaw(ctx, querySQL, RechargeQueryRsp{})
	if err != nil {
		return err
	}

	ret := map[string]interface{}{
		"list":  respTaskList,
		"total": count,
	}

	if ret != nil {

		var (
			residualPoints uint64 // 剩余积分
			rechargePoints uint64 // 充值积分
			bonusPoints    uint64 // 赠送积分
			refundPoints   uint64 // 退款积分
			totalPoints    uint64 //  积分总额
		)
		for _, v := range ret["list"].([]interface{}) {

			respDRs := v.(*RechargeQueryRsp)
			residualPoints += respDRs.ResidualPoints
			rechargePoints += respDRs.RechargePoints
			bonusPoints += respDRs.BonusPoints
			refundPoints += respDRs.RefundPoints
			totalPoints += respDRs.TotalPoints
		}

		ret["all"] = map[string]interface{}{
			"residual_points": residualPoints,
			"recharge_points": rechargePoints,
			"bonus_points":    bonusPoints,
			"refund_points":   refundPoints,
			"total_points":    totalPoints,
		}
	}

	return a.addQueryResponseSeq(pp, ret)
}

func (a *data_Recharge) exportRequestCheck(ctx context.Context, reqArgs map[string]interface{}) error {

	if _, ok := reqArgs["ids"]; !ok {
		return errors.New("请求参数缺失")
	}

	if _, ok := reqArgs["seqs"]; !ok {
		return errors.New("请求参数缺失")
	}
	return nil
}

func (a *data_Recharge) Export(ctx context.Context, item map[string]interface{}) interface{} {

	if err := a.exportRequestCheck(ctx, item); err != nil {
		return err
	}

	var (
		seqs      = make(map[string]string)
		condition = fmt.Sprintf(`
  LEFT JOIN user account_user
    ON account_user.id = recharge.account_id
    AND account_user.deleted = 0
WHERE recharge.id IN (%v)`, strings.Join(strings.Split(item["ids"].(string), "|"), ","))
		querySQL = fmt.Sprintf(`
SELECT
  recharge.id AS id,
  recharge.account_id AS account_id,
  account_user.account AS account_name,
  account_user.leader_id AS leader_id,
  recharge.recharge_points AS recharge_points,
  recharge.bonus_points AS bonus_points,
  recharge.refund_points AS refund_points,
  recharge.total_points AS total_points,
  recharge.residual_points AS residual_points,
  recharge.creator AS creator,
  recharge.create_at AS create_at
FROM recharge
%v
`, condition)
	)

	respTaskList, err := db.QueryRaw(ctx, querySQL, RechargeQueryRsp{})
	if err != nil {
		return err
	}

	selectedItems := []string{
		"id",
		"account_name",
		"residual_points",
		"recharge_points",
		"bonus_points",
		"refund_points",
		"total_points",
		"create_at",
		//"creator_name",
	}
	for i, v := range strings.Split(item["ids"].(string), "|") {
		seqs[v] = strings.Split(item["seqs"].(string), "|")[i]
	}

	req := a.export(ctx, respTaskList, 1, seqs, strings.Join(selectedItems, "|"))
	if req != nil {
		if _, ok := req.(error); ok {
			return req
		}
	}

	return req
}

func (a *data_Recharge) export(ctx context.Context, req interface{}, funcTy int, seqs map[string]string, selectedItems string) interface{} {

	var (
		xlsx       = excelize.NewFile()
		categories = map[string]string{
			"A1": "序号",
			"B1": "充值账户",
			"C1": "剩余积分",
			"D1": "充值积分",
			"E1": "赠送积分",
			"F1": "退款积分",
			"G1": "积分总额",
			"H1": "充值时间",
			//"I1": "充值人员",
		}
		selectedItemMap = make(map[string]int)
		colWidths       = map[string]float64{"A": 8, "B": 22, "C": 18, "D": 8, "E": 8, "F": 8, "G": 20, "H": 20, "I": 12}
	)

	for key, value := range categories {
		xlsx.SetCellValue("Sheet1", key, value)
		_style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["#EEECE1"],"pattern":1},"alignment":{"horizontal":"center","vertical":"center"},"font":{"bold":true,"family":"宋体","size":10}}`)
		if err == nil {
			xlsx.SetCellStyle("Sheet1", key, key, _style)
		}
	}

	xlsx.SetRowHeight("Sheet1", 1, 20)

	for k, v := range colWidths {
		xlsx.SetColWidth("Sheet1", k, k, v)
	}

	for i, v := range strings.Split(fmt.Sprintf("%v", selectedItems), "|") {
		selectedItemMap[v] = i
	}

	p := map[string]struct{}{
		"residual_points": {},
		"recharge_points": {},
		"bonus_points":    {},
		"refund_points":   {},
		"total_points":    {},
	}

	for index, vv := range req.([]interface{}) {

		var (
			columIndex  = 'A'
			columOffset = 1
		)

		for kkk, vvv := range Struct2Map(vv, "json") {

			if len(selectedItemMap) > 0 {
				if i, ok := selectedItemMap[kkk]; !ok {
					continue
				} else {
					columOffset = i
				}
			}

			cell := fmt.Sprintf("%c", int(columIndex)+columOffset) + convert.ToString(index+2)

			if reflect.TypeOf(vvv).Kind() == reflect.Ptr {
				vOf := reflect.ValueOf(vvv)
				if vOf.IsNil() {
					vvv = ""
				} else {
					vvv = vOf.Elem()
				}
			}

			if kkk == "create_at" {
				vvv = Format(vvv.(int64))
			}

			if kkk == "id" {
				vvv = seqs[fmt.Sprintf("%v", vvv.(int64))]
			}

			if _, ok := p[kkk]; ok {
				vvv = Decimal(float64(vvv.(uint64))/10000.0, 5)
			}

			xlsx.SetCellValue("Sheet1", cell, vvv)
		}

		xlsx.SetRowHeight("Sheet1", index+2, 18)
	}

	xlsx.SetSheetName("Sheet1", "第一页")

	fileName, filePath := a.getExportPath(convert.ToString(time.Now().UnixMilli())+".csv", funcTy)
	err := xlsx.SaveAs(fileName)
	if err != nil {
		return nil
	}

	req = filePath

	return req
}

func (a *data_Recharge) getExportPath(fileName string, bizTy int) (string, string) {

	var (
		bizTyMap = map[int]string{
			1: "recharge",
		}
	)

	relativePath := fmt.Sprintf("%v/export/%v", bizTyMap[bizTy], fileName)

	return GetFilePath(
		fmt.Sprintf("%v/%v",
			FileStorage,
			relativePath),
	), relativePath
}

func (a *data_Recharge) addQueryResponseSeq(p PaginationParam, req map[string]interface{}) interface{} {

	if req != nil {

		var enable bool
		if _, ok := req["total"]; ok {
			if _, ok := req["list"]; ok {
				enable = true
			}
		}
		if enable {
			var (
				indexStart = 1
				total      = req["total"].(uint64)
			)

			for i, _ := range req["list"].([]interface{}) {

				//resp := v.(*schemaCustomer.RechargeQueryRsp)
				seqNo := int(total) - (p.PageSize*(p.PageIndex-1) + (int(i) + 1)) + indexStart
				//seqNo := (p.PageSize*(p.PageIndex-1) + (int(i) + 1)) + autoIndexStart
				//req.(map[string]interface{})["list"].([]interface{})[i].(*schemaCustomer.UserQueryRsp).Seq = int64(seqNo)
				req["list"].([]interface{})[i].(*RechargeQueryRsp).SeqNo = int64(seqNo)
			}
		}
	}

	return req
}
func (a *data_Recharge) createRetry(ctx context.Context, items map[string]interface{}, args ...interface{}) error {

	var (
		err           error
		retryCount    = 1
		retryInterval = 100 * time.Millisecond
	)

	if len(args) == 1 {
		retryCount = args[0].(int)
	}
	if len(args) == 2 {
		retryCount, retryInterval = args[0].(int), args[1].(time.Duration)
	}

	for i := 0; i < retryCount; i++ {
		_, err = db.Create(ctx, "recharge", items)
		if err == nil {
			break
		}
		if isLockError(err) || isDeadlineExceededError(err) {
			time.Sleep(retryInterval)
			continue
		}

		return err
	}

	return err
}

func (a *data_Recharge) updateUserRechargeInfo(ctx context.Context, item map[string]interface{}, ty int, args ...interface{}) error {

	var (
		now       = time.Now().Unix()
		updateSQL string
	)
	if ty == 1 {

		var (
			rp uint64
			bp uint64
		)
		if v, ok := item["recharge_points"]; ok {
			rp = v.(uint64)
		}

		if v, ok := item["bonus_points"]; ok {
			bp = v.(uint64)
		}

		updateSQL = fmt.Sprintf(`
		UPDATE 
		    user 
		SET 
		    updated_at = %v,
		    recharge_points = recharge_points + %v,	
		    bonus_points = bonus_points + %v
		WHERE
		    id = %v
`, now, rp, bp, item["account_id"])
	}

	if ty == 2 {
		var userBonusPoints uint64
		if len(args) == 1 {
			userBonusPoints = args[0].(uint64)
		}
		updateSQL = fmt.Sprintf(`
		UPDATE 
		    user 
		SET 
		    updated_at = %v,
		    recharge_points = recharge_points - %v,
		    bonus_points = %v
		WHERE
		    id = %v
`, now, item["refund_points"], userBonusPoints, item["account_id"])
	}

	_, err := db.ExecRaw(ctx, updateSQL)
	return err
}

func (a *data_Recharge) updateRechargeStatistics(args ...interface{}) error {

	type columnType struct {
		LeaderId            *int64  `json:"leader_id" db:"leader_id"`
		LeaderName          *string `json:"leader_name" db:"leader_name"`
		AccountId           int64   `json:"account_id" db:"account_id"`
		RechargePointsTotal uint64  `json:"recharge_points_total" db:"recharge_points_total"`
		BonusPointsTotal    uint64  `json:"bonus_points_total" db:"bonus_points_total"`
	}

	var (
		t           = time.Now()
		condition   = " GROUP BY account_id,creator"
		startDate   = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
		endDate     = startDate.AddDate(0, 0, 1)
		leftJoinSQL = fmt.Sprintf("INNER JOIN (%v) leader_user ON leader_user.id = recharge_statistics_users.creator", fmt.Sprintf(`
			SELECT 
				id as id,
				id as leader_id,
				account as leader_account
			FROM 
				user
			GROUP BY id,account
`))
	)

	if len(args) == 1 {
		startDate = args[0].(time.Time)
	}
	if len(args) == 2 {
		startDate, condition = args[0].(time.Time), fmt.Sprintf("AND account_id = %v", args[1].(uint64))+condition
	}

	for now := startDate; !now.After(endDate); now = now.AddDate(0, 0, 1) {
		var (
			start = time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, now.Location()).Unix()
			end   = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Unix()

			querySQL = fmt.Sprintf(`
		SELECT
			leader_user.leader_id AS leader_id,
			leader_user.leader_account AS leader_name,
			recharge_statistics_users.account_id AS account_id,
			recharge_statistics_users.recharge_points_total,
			recharge_statistics_users.bonus_points_total
		FROM (
			SELECT
				account_id,
				creator,
				SUM(recharge_points) AS recharge_points_total,
				SUM(bonus_points) AS bonus_points_total
			FROM recharge
				WHERE recharge.create_at >= %v AND recharge.create_at <= %v
		    %v
		) recharge_statistics_users
		%v
	`, start, end, condition, leftJoinSQL)
		)

		log.Info(fmt.Sprintf("start:%v end:%v sql:%+v", Format(start), Format(end), querySQL))

		req, err := db.QueryRaw(context.Background(), querySQL, columnType{})
		if err != nil {
			return err
		}

		for _, v := range req {

			vv := v.(*columnType)
			var leaderId int64
			var leaderName string
			if vv.LeaderId != nil {
				leaderId = *vv.LeaderId
			}
			if vv.LeaderName != nil {
				leaderName = *vv.LeaderName
			}
			var (
				tableName = "daily_recharge_statistics"
				entity    = DailyRechargeStatistics{}
				startD    = time.Unix(start, 0)
				date      = fmt.Sprintf("%04v-%02v-%02v", startD.Year(), int(startD.Month()), startD.Day())
				item      = map[string]interface{}{
					"date":                  date,
					"recharge_points_total": vv.RechargePointsTotal,
					"bonus_points_total":    vv.BonusPointsTotal,
					"account_id":            vv.AccountId,
					"leader_id":             leaderId,
					"leader_name":           leaderName,
					"create_at":             now.Unix(),
					"updated_at":            now.Unix(),
				}
				checkDupSQL = fmt.Sprintf(`
			SELECT 
			    * 
			FROM %v
			WHERE
			     leader_id = %v AND account_id = %v AND date = '%v'
`, tableName, leaderId, vv.AccountId, date)
			)

			log.Info(fmt.Sprintf("date:%v check dup sql:%+v", date, checkDupSQL))

			req, err = db.QueryRaw(context.Background(), checkDupSQL, entity)
			if err != nil {
				log.Err("create daily recharge err:%+v", err)
				continue
			}

			if req == nil {
				if _, err := db.Create(context.Background(), tableName, item); err != nil {
					log.Err("create daily recharge err:%+v", err)
				}
				continue
			}

			s := req[0].(*DailyRechargeStatistics)
			if s.RechargePointsTotal == vv.RechargePointsTotal && s.BonusPointsTotal == vv.BonusPointsTotal {
				continue
			}

			var (
				queries = map[string]interface{}{
					"id": s.ID,
				}
				updateKeys = map[string]interface{}{
					"recharge_points_total": vv.RechargePointsTotal,
					"bonus_points_total":    vv.BonusPointsTotal,
					"leader_name":           leaderName,
					"updated_at":            now.Unix(),
				}
			)

			if err := db.Update(context.Background(), tableName, updateKeys, queries); err != nil {
				log.Err("update daily recharge err:%+v", err)
			}
		}
	}

	return nil
}
